

function addformvdocover()
{

   
    $("#addform").append('<div id="feature'+rowdiv+'" class="itPlg addVdoYtCvPlg featureclass" alt="'+rowdiv+'">'+dataform['vdocover']+"</div>");
    var rownow=rowdiv;
    
    
    $('#feature'+rownow+' .linkvdobutton').click(function() {
    
        popupvdocover(rownow);
    
    
    });
    
    $('#feature'+rownow+' .deleterowbutton').click(function(){
   
    $('#feature'+rownow).remove();
    
   });
   
   
   $('#feature'+rownow+' .deletevdobutton').click(function(){
   
    $('#feature'+rownow+' .vdoclass iframe').remove();
    
   });
   
   
   $('#feature'+rownow+' .imgvdobutton').click(function(){
 
 getcoverdata(rownow);
 

   
   });
   
   
   

    
    
    
    
    rowdiv++;

}
function popupvdocover(index)
{

//var code = '<div style="padding:10px;background:#fff" id="inline_content">\n';
//code += '<p><strong>Link</strong></p>\n';

//code += '<p style="text-align:center"><input type="text" name="linkvdo[]" id="linkvdo" ></p>\n';
//code += '<p><input type="button" value="OK" onclick="addvdolinkcover('+index+')" ><input type="button" value="Cancel" onclick="$.colorbox.close();" ></p>\n';
//code += '\n';
//code += '</div>';

// $.colorbox({html:code,width:($(window).width()-850),height:($(window).height()-100),maxWidth:'100%',maxHeight:'100%' });


var code = '<div class="popGen posPop">\n';
code += '<div class="topGen clBd2 bdBtm">\n';
code += '<div class="wrpTtlGen">\n';
code += '<h1 class="ttlGen clTxt2 fs05">Insert Video Link</h1>\n';
code += '</div>\n';
code += '<div class="btnIco closeGen" onclick="closepopup()" >\n';
code += '<span class="ico icoCloseGen"></span>\n';
code += '</div>\n';
code += '<div class="topBgGen clBg3"></div>\n';
code += '</div>\n';
code += '<div class="bodyGen clBg3">\n';
code += '<div class="bodyOutGen">\n';
code += '<div class="bodyInGen">\n';
code += '<p class="desAddGen clTxt3 fs03">Insert the URL link of video (Youtube only).</p>\n';
code += '<form class="wrpFrmGen" onsubmit="return false;">\n';
code += '<fieldset class="wrpFrmInpTxt">\n';
code += '<div class="wrpInFrmInpTxt">\n';
code += '<input class="frmInpTxt frmGen clBg4 clTxt3 fs03" name="linkvdo[]" id="linkvdo"  type="text" autofocus required>\n';
code += '</div>\n';
code += '</fieldset>\n';
code += '<div class="wrpBtnGen">\n';
code += '<input type="submit" class="btnGen clTxtW cutTxt clBgSp2 fs04" value="Insert" onclick="addvdolinkcover('+index+')"  >\n';
code += '<input type="button" class="btnGen clTxtW cutTxt clBgBt1 fs04" value="Cancel" onclick="closepopup()"  >\n';
code += '</div>\n';
code += '</form>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>';

$('.ovlPopGen.wrpPopAddPop').html(code);
$('.ovlPopGen.wrpPopAddPop').show(); 


}
function addvdolinkcover(index)
{

   //console.log($("#linkvdo").val());
   if($("#linkvdo").val()!="")
   {
   var youtube=youtube_parser($("#linkvdo").val());
   
   
   if(youtube)
   {
   $('#feature'+index+' .vdoclass').html('<iframe width="640" height="360" src="http://www.youtube.com/embed/'+youtube+'?wmode=transparent" frameborder="0" allowfullscreen></iframe>');
   //$.colorbox.close();
   
   }else
   {
    var vimeo=vimeo_parser($('#linkvdo').val());
    if(vimeo)
    {
    
    
    $('#feature'+index+' .vdoclass').html('<iframe width="640" height="360" src="http://player.vimeo.com/video/'+vimeo+'?wmode=transparent" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>');
    
    }else
    {
    var ext = $('#linkvdo').val().split('.').pop().toLowerCase();
        if(ext=="mp4") {
        $('#feature'+index+' .vdoclass').html('<video width="640" height="360" controls><source src="'+$('#linkvdo').val()+'" type="video/mp4"></video> ');

        }
    
    
    
    //alertbox("no suppost");
    }
   
   
   }
   
   closepopup();
   }else
   {
     alertbox('โปรดกรอก link vdo ');
   
   }
   

}
function saveformvdocover(id,plugid)
{
var obj={};
var url,embed;
if($("#"+id+' .vdoclass').html()!="")
{

url=$("#"+id+' iframe').attr("src");
if(typeof  url== "undefined")
{
url=$("#"+id+' video source').attr("src");
if(typeof  url!= "undefined")
{
var ext = url.split('.').pop().toLowerCase();
if(ext=="mp4") 
{
embed=url.split('/').pop();

}
else
{
embed="";
}
}else
{
url="";
embed="";

}

}else
{
youtube=youtube_parser(url);
if(youtube)
{
embed=youtube;
}else
{
vimeo=vimeo_parser(url);

if(vimeo)
{
embed=vimeo;

}else
{

embed="";


}

}
}

}else
{

url="";
embed="";
}

var rowdata=$("#"+id).attr('alt');

obj={plugid:plugid,url:url,embed:embed,
simgmid:$('#imgdata-'+rowdata+' .image1 input[name="simgmid[]"]').val(),
detail:$("#"+id+' input[name="detail[]"]').val(),
imgmid:$('#imgdata-'+rowdata+' .image1 input[name="imgmid[]"]').val()


};
return obj;

}
function getformvdocover(dataplugin)
{
//console.log(dataplugin);
var code = '<div class="ldIt wrpVdoLd clBg4 w640" id="vdodatasetnow-'+dataplugin.vdoid+'">\n';
//code += '<div class="icoDefLd">\n';
//code += '<span class="ico icoVdoDefLd"></span>\n';
//code += '<span>Video</span>\n';
//code += '</div>\n';

//code +=' <iframe width="100%" height="360" src="'+dataplugin.url+'"> </iframe>';
var n = dataplugin.url.search("youtu.be");
if(n>0)
{
var youpath= youtube_parser(dataplugin.url);
dataplugin.url='https://www.youtube.com/embed/'+youpath+'?wmode=transparent';
}


code += '</div><input type="hidden" name="vdoidvdo[]" value="'+dataplugin.vdoid+'"><input type="hidden" name="urlvdo[]" value="'+dataplugin.url+'">';
return code;

}
function editformvdocover(datarow)
{
addformvdocover();
var rownow= rowdiv-1;


var ext = datarow.url.split('.').pop().toLowerCase();
if(ext=="mp4") 
{
$('#feature'+rownow+' .vdoclass').html(' <video width="100%" height="360" controls><source src="'+datarow.url+'" type="video/mp4"></video>');
}else
{
$('#feature'+rownow+' .vdoclass').html('<iframe width="640" height="360" src="'+datarow.url+'" frameborder="0" allowfullscreen></iframe>');
}



        getcoverdata(rownow,1);
       
       $('#imgdata-'+rownow+' .image1 input[name="simgmid[]"]').val(datarow.simgmid);
       $('#feature'+rownow+'  input[name="detail[]"]').val(datarow.detail);
       $('#imgdata-'+rownow+' .image1 input[name="imgmid[]"]').val(datarow.imgmid);
       $('#imgdata-'+rownow+' .image1 .plgAreaThumbnail').html('<a target="_blank" href="'+datarow.img.newpath+'?t='+Math.floor((Math.random()*100000)+1)+'"><img  width="150" src="'+datarow.simg.newpath+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');



}